﻿#include <iostream>
#include <string>
#include <cmath>
using namespace std;

bool isPrime(int num) {
	if (num <= 1) {
		return false;
	}
	for (int i = 2; i <= sqrt(num); i++) {
		if (num % i == 0) {
			return false;
		}
	}
	return true;
}

int findClosestPrime(int n) {
	int closestPrime = n;
	int diff = 0;

	while (true) {
		if (isPrime(closestPrime - diff)) {
			return closestPrime - diff;
		}
		if (isPrime(closestPrime + diff)) {
			return closestPrime + diff;
		}
		diff++;
	}
}

int main() {
	string text;
	int n = 0, s = 2, m = 0;
	while (s >= 0) {
		cin >> text;
		if (text != "zero" && text != "one" && text != "two" && text != "three" && text != "four" && text != "five" && text != "six" && text != "seven" && text != "eight" && text != "nine") {
			m++;
			break;
		}
		else {
			if (text == "zero") {
				n += 0 * pow(10, s);
			}
			else if (text == "one") {
				n += 1 * pow(10, s);
			}
			else if (text == "two") {
				n += 2 * pow(10, s);
			}
			else if (text == "three") {
				n += 3 * pow(10, s);
			}
			else if (text == "four") {
				n += 4 * pow(10, s);
			}
			else if (text == "five") {
				n += 5 * pow(10, s);
			}
			else if (text == "six") {
				n += 6 * pow(10, s);
			}
			else if (text == "seven") {
				n += 7 * pow(10, s);
			}
			else if (text == "eight") {
				n += 8 * pow(10, s);
			}
			else if (text == "nine") {
				n += 9 * pow(10, s);
			}
		}
		s--;
	}
	if (m == 0) {
		int closestPrime = findClosestPrime(n);
		std::cout << closestPrime << endl;
	}
	else {
		std::cout << "Wrong input" << endl;
	}
	return 0;
}